# !/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 2022/8/14 16:39
# @Author : xyjiang1216
# @Email : jiangxuyan@nudt.edu.cn
# @File : ui_main.py
# @Version: OpenTSN_planner_builder 1.0
import sys

from PySide6.QtCore import QSize, QPointF
from PySide6.QtGui import QIcon
from PySide6.QtWidgets import QMainWindow, QApplication, QGraphicsScene, QPushButton

from UI.ui.test_ui import Ui_Form

from qt_material import apply_stylesheet


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.line_item = None
        self.ui = Ui_Form()
        self.ui.setupUi(self)

        self.setWindowIcon(QIcon('../img/win_logo.png'))

        self.graph_scene = QGraphicsScene()

        button = QPushButton('')
        # button.resize(30, 30)
        button.setMaximumSize(30, 30)
        button.setMaximumSize(30, 30)
        icon = QIcon()
        icon.addFile('img/sw_mini.png')
        button.setIcon(icon)
        button.setIconSize(QSize(30, 30))
        # button.setFlat(True)
        # button.setStyleSheet("QPushButton{background:rgba(0,0,0,0);border:1px solid rgba(0,0,0,0);}")
        button.setStyleSheet("QPushButton{background:rgba(0,0,0,0);border:1px solid rgba(0,0,0,0);}"
                             "QPushButton:hover{background-color: rgb(119,136,153);border:none;color:rgb(255, 255, "
                             "255);} "
                             "QPushButton:checked{background-color: rgb(119,136,153);border:none;color:rgb(255, 255, "
                             "255);}")

        # handle = QGraphicsRectItem(QRect(10, 10, 50, 50))
        # proxy = QGraphicsProxyWidget(handle)
        #
        # proxy.setWidget(button)
        # handle.setBrush(QtCore.Qt.blue)
        # self.graph_scene.addItem(handle)
        proxy = self.graph_scene.addWidget(button)
        proxy.setPos(QPointF(50, 50))

        button = QPushButton('')
        # button.resize(30, 30)
        button.setMaximumSize(30, 30)
        button.setMaximumSize(30, 30)
        icon = QIcon()
        icon.addFile('img/sw_mini.png')
        button.setIcon(icon)
        button.setIconSize(QSize(30, 30))
        # button.setFlat(True)
        # button.setStyleSheet("QPushButton{background:rgba(0,0,0,0);border:1px solid rgba(0,0,0,0);}")
        button.setStyleSheet("QPushButton{background:rgba(0,0,0,0);border:1px solid rgba(0,0,0,0);}"
                             "QPushButton:hover{background-color: rgb(119,136,153);border:none;color:rgb(255, 255, "
                             "255);} "
                             "QPushButton:checked{background-color: rgb(119,136,153);border:none;color:rgb(255, 255, "
                             "255);}")
        proxy = self.graph_scene.addWidget(button)
        proxy.setPos(QPointF(100, 100))

        # pixmap = QPixmap('img/sw_mini.png')
        # item2 = self.graph_scene.addPixmap(pixmap)
        #
        # item2.setPos(QPointF(50, 50))

        self.ui.graphicsView.setScene(self.graph_scene)

    #     # 半物理路径区域拓扑图初始化显示
    #     item1_x = 0
    #     item1_y = 70
    #     item2_x = 500
    #     item2_y = 70
    #     item3_x = 250
    #     item3_y = 0
    #     item4_x = 250
    #     item4_y = 140
    #     radius = 12
    #
    #     # 添加交换机
    #     # item1 = self.graph_scene.addEllipse(item1_x, item1_y, radius, radius, QPen(Qt.black), QBrush(QColor(Qt.blue)))
    #     # item2 = self.graph_scene.addEllipse(item2_x, item2_y, radius, radius, QPen(Qt.black), QBrush(QColor(Qt.blue)))
    #     # item3 = self.graph_scene.addEllipse(item3_x, item3_y, radius, radius, QPen(Qt.black), QBrush(QColor(Qt.blue)))
    #     # item4 = self.graph_scene.addEllipse(item4_x, item4_y, radius, radius, QPen(Qt.black), QBrush(QColor(Qt.blue)))
    #
    #     # 添加线
    #     # line_pen = QPen(Qt.blue)
    #     # line_pen.setWidth(3)
    #     # l1 = self.graph_scene.addLine(item1_x + radius / 2, item1_y + radius / 2, item3_x + radius / 2,
    #     #                               item3_y + radius / 2, line_pen)
    #     # l2 = self.graph_scene.addLine(item3_x + radius / 2, item3_y + radius / 2, item2_x + radius / 2,
    #     #                               item2_y + radius / 2, line_pen)
    #     # l3 = self.graph_scene.addLine(item1_x + radius / 2, item1_y + radius / 2, item4_x + radius / 2,
    #     #                               item4_y + radius / 2, line_pen)
    #     # l4 = self.graph_scene.addLine(item4_x + radius / 2, item4_y + radius / 2, item2_x + radius / 2,
    #     #                               item2_y + radius / 2, line_pen)
    #     # self.switch_item = {'sw1': item1, 'sw2': item2, 'sw3': item3, 'sw4': item4}
    #     # self.line_item = {('sw1', 'sw3'): l1, ('sw3', 'sw2'): l2, ('sw1', 'sw4'): l3, ('sw4', 'sw2'): l4}
    #     line_pen = QPen(Qt.black)
    #     line_pen.setWidth(1)
    #     l1 = self.graph_scene.addLine(item1_x + 25,
    #                                   item1_y + 25,
    #                                   item2_x + 25,
    #                                   item2_y + 25,
    #                                   line_pen)
    #     # self.switch_item = {'sw1': item1, 'sw2': item2}
    #     # self.line_item = {('sw1', 'sw3'): l1}
    #
    #
    #     button = QPushButton('', self)
    #     button.resize(50, 50)
    #     self.item1_button = self.graph_scene.addWidget(button)
    #     print(type(self.item1_button))
    #
    #     self.item1_button.resize(10, 10)
    #     self.item1_button.show()
    #     self.item1_button.setPos(item1_x, item1_y)
    #
    #     # pixmap = pixmap.scaled(50, 50)
    #     pixmap = QPixmap('img/sw_mini.png')
    #     self.item1 = self.graph_scene.addPixmap(pixmap)
    #
    #     item1_pos = QPointF(item1_x, item1_y)
    #     self.item1.setPos(item1_pos)
    #
    #     pitem = QGraphicsPixmapItem(pixmap)
    #     self.item1 = self.graph_scene.addItem(pitem)
    #
    #     pixmap = QPixmap('img/sw_mini.png')
    #     item2 = self.graph_scene.addPixmap(pixmap)
    #     item2_pos = QPointF(item2_x, item2_y)
    #     item2.setPos(item2_pos)
    #
    #     # 添加交换机名称
    #     # text1 = self.graph_scene.addSimpleText('sw1')
    #     # text2 = self.graph_scene.addSimpleText('sw2')
    #     # text3 = self.graph_scene.addSimpleText('sw3')
    #     # text4 = self.graph_scene.addSimpleText('sw4')
    #
    #     # text1_pos = QPointF(item1_x, item1_y + radius)
    #     # text1.setPos(text1_pos)
    #     #
    #     # text2_pos = QPointF(item2_x, item2_y + radius)
    #     # text2.setPos(text2_pos)
    #     #
    #     # text3_pos = QPointF(item3_x, item3_y + radius)
    #     # text3.setPos(text3_pos)
    #     #
    #     # text4_pos = QPointF(item4_x, item4_y - radius)
    #     # text4.setPos(text4_pos)
    #
    #     # 添加图示标注
    #     text5 = self.graph_scene.addSimpleText('绿色线 表示当前路由')
    #     text5.setPen(QPen(Qt.black))
    #     text5_pos = QPointF(400, 0)
    #     text5.setPos(text5_pos)
    #
    #
    #     # 把graphScene容器添加到graphView中
    #     self.ui.graphicsView.setScene(self.graph_scene)
    #
    #     # self.ui.graphicsView.setDragMode(QGraphicsView.ScrollHandDrag)
    #
    #     self.graph_scene.mousePressEvent = self.scene_MousePressEvent
    #
    # def pixmap_MousePressEvent(self, event):
    #     # if event.button() == QtCore.Qt.LeftButton:  # 左键按下
    #     # print("鼠标左键单击")  # 响应测试语句
    #     # print(event.scenePos())
    #     # self.preMousePosition = event.scenePos()  # 获取鼠标当前位置
    #     if event.button() == QtCore.Qt.RightButton:  # 右键按下
    #         print("鼠标右键单击")  # 响应测试语句
    #         print(self.item1.pos())
    #         self.item1.setSelected(True)
    #
    # def scene_MousePressEvent(self, event):
    #     if event.button() == QtCore.Qt.LeftButton:  # 左键按下
    #         print("鼠标左键单击")  # 响应测试语句
    #         # print(event.scenePos())
    #         # self.preMousePosition = event.scenePos()  # 获取鼠标当前位置
    #         # if event.button() == QtCore.Qt.RightButton:  # 右键按下
    #         #     print("鼠标右键单击")  # 响应测试语句
    #         print(event.scenePos())


if __name__ == '__main__':
    app = QApplication([])
    window = MainWindow()

    apply_stylesheet(app, theme='dark_teal.xml')
    # https://github.com/UN-GCPDS/qt-material/blob/master/README.md#usage

    window.show()
    sys.exit(app.exec())
